#pragma once

#include "../../plugin/base/framework.hh"
#include "../../corelib/singleton.hpp"

// User implemented framework
// @see Framework
class LuaFramework : public Framework {
    std::string rootPath_;
public:
    LuaFramework();
    virtual ~LuaFramework();
    virtual bool onInstall(kconfig::Config* config) override;
    virtual bool onUninstall() override;
    virtual bool onStart(kconfig::Config* config) override;
    virtual bool onStop() override;
    virtual void onTick(std::time_t millionseconds) override;
    virtual void onPathJoin(PathID pathID, SiteType siteType, UserData userData) override;
    virtual void onPathDisjoin(PathID pathID, SiteType siteType) override;
    virtual void onFindPathTimeout(SiteType siteType, UserData userData) override;
    virtual void onEntityFound(std::uint32_t type, const EntityIDVector& ids, std::uint64_t userData) override;

public:
    const std::string& getRootScript() const;
};

// singleton of user framework
// NOTICE the name 'FrameworkRef' MUST NOT change
#define FrameworkRef (*kratos::corelib::Singleton<LuaFramework>::instance())
#define FrameworkSingleton kratos::corelib::Singleton<LuaFramework>

#ifdef verblog
#undef verblog
#define verblog (ModuleRef.getLogverb() << "[lua]")
#endif // verblog
#ifdef debuglog
#undef debuglog
#define debuglog (ModuleRef.getLogdebug() << "[lua]")
#endif // debuglog
#ifdef warnlog
#undef warnlog
#define warnlog (ModuleRef.getLogwarn() << "[lua]")
#endif // warnlog
#ifdef errorlog
#undef errorlog
#define errorlog (ModuleRef.getLogerror() << "[lua]")
#endif // errorlog
#ifdef fatallog
#undef fatallog
#define fatallog (ModuleRef.getLogfatal() << "[lua]")
#endif // fatallog
#define endlog (ModuleRef.getLogend())

#ifdef logverb
#undef logverb
#endif // logverb
#ifdef logdebug
#undef logdebug
#endif // logdebug
#ifdef logwarn
#undef logwarn
#endif // logwarn
#ifdef logerror
#undef logerror
#endif // logerror
#ifdef logfatal
#undef logfatal
#endif // logfatal
